package drrr.orm;

import java.util.List;

/**
 * the example class for the Interface of Service
 * Created by Xun on 2015/4/18.
 */
public class UserService extends Service {

    @Override
    public List getAllEntities() {
        return getAllDao().getUserDao().getAllEntities();
    }

    /**
     * insert a new object to the database
     *
     * @param entityRef
     */
    public void insert(Entity entityRef) {
        getAllDao().getUserDao().insert((UserEntity) entityRef);
    }

    /**
     * Update the modified object
     *
     * @param entityRef the modified object
     */
    public void update(Entity entityRef) {
        getAllDao().getUserDao().update((UserEntity) entityRef);
    }

    public void delete(Entity entityRef) {
        getAllDao().getUserDao().delete((UserEntity) entityRef);
    }


    /**
     * Check that is the pair of username and password is legal
     *
     * @param username username
     * @param password password
     * @return null if illegal,the object of UserEntity else
     */
    public UserEntity isLegal(String username, String password) {
        UserEntity userEntity = getAllDao().getUserDao().getUserEntity(username);
        if (userEntity != null && userEntity.getPassword().equals(password)) {
            return userEntity;
        } else {
            return null;
        }
    }

    public UserEntity getUserEntity(int id) {
        return getAllDao().getUserDao().getUserEntity(id);
    }
}
